<html>
<!-- Head tag -->
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	
	
		<link href="/favicon.ico" rel="icon">
	 
      <title>Teiid搭建和使用小记 | BiJii&#39;s Blog</title>
	<link rel="stylesheet" href="/css/font-awesome/css/font-awesome.css">
	<link rel="stylesheet" href="/css/style.css">
	<link rel="stylesheet" href="/css/highlight.css">
	
    <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?542b4962c3c4035fce9071b7c665f0d2";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>

	
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-97838175-1', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->


</head>
<body>
	<div id="site" class="site">
		<div id="sidebar" class="sidebar">
			<header id="header" class="site-header">
	<div class="site-branding">
		<h1 class="site-title"><a href="/" rel="home">BiJii&#39;s Blog</a></h1>
		<p class="site-description">认认真真...</p>
		<button class="secondary-toggle font-asesome-icon">Menu and widgets</button>
	</div>
</header>
<div id="secondary" class="secondary">
	<nav class="main-navigation">
                         <ul id="menu-demo-menu" class="nav-menu">
						 
							<li class="menu-item"><a href="/">首页</a></li>
						
							<li class="menu-item"><a href="/archives">归档</a></li>
						
							<li class="menu-item"><a href="/about">关于</a></li>
						
                         </ul>
    </nav>
	
		
<aside class="widget">
		<h3 class="widget-title">归档</h3>		
		<ul>
			<ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">1</span></li></ul>
		</ul>
	</aside>


	
		
<aside class="widget">
		<h3 class="widget-title">最新文章</h3>		
		<ul>
			
          <li>
            <a href="/2017/12/08/TeiidUseNote/">Teiid搭建和使用小记</a>
          </li>
        
          <li>
            <a href="/2017/11/16/HexoOSChina/">Hexo+OSChina搭建免费个人博客</a>
          </li>
        
          <li>
            <a href="/2017/06/12/DatatablesStruts/">Struts2+DataTables动态生成数据表</a>
          </li>
        
		</ul>
	</aside>


	
		
  <aside class="widget">
		<h3 class="widget-title">标签云</h3>
        <a href="/tags/Datatables/" style="font-size: 10px;">Datatables</a> <a href="/tags/Hexo/" style="font-size: 10px;">Hexo</a> <a href="/tags/Teiid/" style="font-size: 10px;">Teiid</a>
    </aside>

	
</div>
		</div>
		<div id="content" class="site-content">
			<main id="main" class="site-main" role="main">
				
<article class="hentry ">
		
		
			<header class="entry-header">
				<h2 class="entry-title"><a href="/2017/12/08/TeiidUseNote/" rel="bookmark">Teiid搭建和使用小记</a></h2>	
			</header>
		
		<!-- .entry-header -->
		<div class="entry-content">
			
				<h4 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h4><ol>
<li><a href="http://blog.csdn.net/scorpio3k/article/details/24466065" target="_blank" rel="external">Teiid 基于数据联邦的集成方案</a></li>
<li><a href="http://www.cnblogs.com/biaobiaoqi/p/3753761.html" target="_blank" rel="external">数据集成工具Teiid Designer的环境搭建</a></li>
<li><a href="http://www.cnblogs.com/biaobiaoqi/p/3409691.html" target="_blank" rel="external">数据集成工具：Teiid实践</a></li>
<li><a href="http://teiid.jboss.org/docs/" target="_blank" rel="external">teiid-quickstarts</a></li>
<li><a href="http://teiid.jboss.org/docs/" target="_blank" rel="external">teiid-documents</a></li>
</ol>
<h4 id="引言"><a href="#引言" class="headerlink" title="引言"></a>引言</h4><blockquote>
<p>Teiid 可以让你用 JDBC + SQL 来访问企业的任何数据，并可对这些不同源的数据进行联合查询。</p>
</blockquote>
<h4 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h4><ul>
<li>操作系统：Windows 7 x64</li>
<li>JDK版本：jdk1.8.0_11</li>
<li>Teiid Server：<a href="https://repository.jboss.org/nexus/service/local/repositories/releases/content/org/jboss/teiid/teiid/9.3.5/teiid-9.3.5-wildfly-server.zip" target="_blank" rel="external">teiid-9.3.5-wildfly-server.zip</a></li>
<li>IDE工具：Eclipse Neon Release (4.6.0)</li>
<li>Eclipse插件：<a href="http://download.jboss.org/jbosstools/neon/stable/updates/" target="_blank" rel="external">JBOSS TOOLS</a></li>
<li>Eclipse插件：<a href="http://download.jboss.org/jbosstools/updates/release/neon/integration-stack/teiiddesigner/11.0.1.Final/" target="_blank" rel="external">Teiid Designer 11.0.1</a></li>
</ul>
<h4 id="Teiid-Server安装"><a href="#Teiid-Server安装" class="headerlink" title="Teiid Server安装"></a>Teiid Server安装</h4><ol>
<li><p>下载并安装JDK</p>
<p> 建议下载安装Java 7以上，这里装的是jdk1.8.0_11。</p>
</li>
<li><p>下载并安装Teiid Server</p>
<ol>
<li>下载安装的是集成wildfly的版本：teiid-9.3.5-wildfly-server.zip</li>
<li>下载后解压至C:\teiid-9.3.5，路径名<strong>不要有空格</strong>，所以不要装在Program Files中</li>
<li>命令行运行cd，进入Teiid安装目录的bin文件夹，比如：cd C:\teiid-9.3.5\bin</li>
<li><p>安装Teiid独立模式服务器，运行standalone.bat和jboss-cli.bat</p>
<p>启动服务器，运行：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">C:\Users\Administrator&gt;cd C:\teiid-9.3.5\bin</div><div class="line">C:\teiid-9.3.5\bin&gt;standalone.bat</div></pre></td></tr></table></figure>
<p>接着打开另一个命令窗口，运行：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">C:\Users\Administrator&gt;cd C:\teiid-9.3.5\bin</div><div class="line">C:\teiid-9.3.5\bin&gt;jboss-cli.bat --connect --file=scripts/teiid-standalone-mode-install.cli</div><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat</div></pre></td></tr></table></figure>
</li>
</ol>
</li>
</ol>
<pre><code>5. 创建Teidd服务器admin用户和应用用户，运行add-user.bat

创建admin用户：

<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat</div><div class="line"></div><div class="line">What type of user do you wish to add?</div><div class="line">a) Management User (mgmt-users.properties)</div><div class="line">b) Application User (application-users.properties)</div><div class="line">(a): a</div><div class="line">Enter the details of the new user to add.</div><div class="line">Using realm &apos;ManagementRealm&apos; as discovered from the existing property files.</div><div class="line">Username : admin</div><div class="line">The username &apos;admin&apos; is easy to guess</div><div class="line">Are you sure you want to add user &apos;admin&apos; yes/no? yes</div><div class="line">Password :</div><div class="line">Re-enter Password :</div><div class="line">What groups do you want this user to belong to? (Please enter a comma separated list,</div><div class="line">or leave blank for none)[ ]:</div><div class="line">About to add user &apos;admin&apos; for realm &apos;ManagementRealm&apos;</div><div class="line">Is this correct yes/no? yes</div><div class="line">Is this new user going to be used for one AS process to connect to another AS process?</div><div class="line">yes/no? no</div></pre></td></tr></table></figure>

创建应用用户：

<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat</div><div class="line"></div><div class="line">What type of user do you wish to add?</div><div class="line">a) Management User (mgmt-users.properties)</div><div class="line">b) Application User (application-users.properties)</div><div class="line">(a): b</div><div class="line">Enter the details of the new user to add.</div><div class="line">Using realm &apos;ApplicationRealm&apos; as discovered from the existing property files.</div><div class="line">Username : user</div><div class="line">Password :</div><div class="line">Re-enter Password :</div><div class="line">What groups do you want this user to belong to? (Please enter a comma separated list,</div><div class="line">or leave blank for none)[ ]: odata</div><div class="line">About to add user &apos;user&apos; for realm &apos;ApplicationRealm&apos;</div><div class="line">Is this correct yes/no? yes</div><div class="line">Is this new user going to be used for one AS process to connect to another AS process?</div><div class="line">yes/no? no</div></pre></td></tr></table></figure>

或者，可以直接快速创建：

<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat -a -u dashboardAdmin -p password1! -g admin</div><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat -a -u teiidUser -p password1! -g user</div><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat -a -u restUser -p password1! -g rest</div><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat -a -u odataUser -p password1! -g odata</div><div class="line">C:\teiid-9.3.5\bin&gt;add-user.bat admin password1!</div></pre></td></tr></table></figure>
</code></pre><h4 id="Teiid-Server运行"><a href="#Teiid-Server运行" class="headerlink" title="Teiid Server运行"></a>Teiid Server运行</h4><h5 id="命令窗口中启动-Teiid-Server"><a href="#命令窗口中启动-Teiid-Server" class="headerlink" title="命令窗口中启动 Teiid Server"></a>命令窗口中启动 Teiid Server</h5><p>打开命令窗口，进入Teiid安装目录bin下，运行standalone.bat：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">C:\Users\Administrator&gt;cd C:\teiid-9.3.5\bin</div><div class="line">C:\teiid-9.3.5\bin&gt;standalone.bat</div></pre></td></tr></table></figure></p>
<p>如果不使用默认设置运行，在后面添加自定义设置的文件名名：-c {configuration.file}：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">C:\Users\Administrator&gt;cd C:\teiid-9.3.5\bin</div><div class="line">C:\teiid-9.3.5\bin&gt;standalone.bat -c standalone-teiid.xml</div></pre></td></tr></table></figure></p>
<p>在浏览器中输入<a href="http://localhost:8080/进入到" target="_blank" rel="external">http://localhost:8080/进入到</a> JBoss 欢迎界面，点击界面上的“Administration Console”链接就看到管理界面。</p>
<h5 id="Eclipse中启动-Teiid-Server"><a href="#Eclipse中启动-Teiid-Server" class="headerlink" title="Eclipse中启动 Teiid Server"></a>Eclipse中启动 Teiid Server</h5><ol>
<li>在 Eclipse中安装JBOSS TOOLS插件<ol>
<li>打开 Eclipse，选择 Help &gt; Install New Software</li>
<li>地址栏输入如下地址：<a href="http://download.jboss.org/jbosstools/neon/stable/updates/" target="_blank" rel="external">http://download.jboss.org/jbosstools/neon/stable/updates/</a></li>
<li>选择出现的所有插件，一直点击下一步，安装完毕后，重启Eclipse</li>
</ol>
</li>
<li>在 Eclipse中配置 Teiid server<ol>
<li>打开 Eclipse，在视图 Servers中右键选择 New &gt; Server</li>
<li>选择对应于安装的 Server 类型，JBoss Community &gt; WildFly 10.x，点下一步</li>
<li>选择 Create new runtime (next page)，其他默认，点下一步</li>
<li>设置WildFly安装路径(C:\teiid-9.3.5)，选择启动的配置文件standalone-teiid.xml，点完成</li>
<li>双击视图 Servers 中新建的 WildFly Server名，打开配置页面 Overview</li>
<li>配置 Management Login Credentials，使用之前设置的admin账号和密码</li>
<li>启动服务器，在Server配置页Teiid Instance中填入JDBC的用户名和密码，测试连接成功后保存设置<blockquote>
<p>JDBC的用户名和密码默认是 user:user，在$JBOSS_HOME/standalone/configuration/teiid-security-users.properties中配置。</p>
</blockquote>
</li>
</ol>
</li>
</ol>
<h4 id="虚拟数据库（VDB）建立"><a href="#虚拟数据库（VDB）建立" class="headerlink" title="虚拟数据库（VDB）建立"></a>虚拟数据库（VDB）建立</h4><h5 id="手动创建和部署VDB"><a href="#手动创建和部署VDB" class="headerlink" title="手动创建和部署VDB"></a>手动创建和部署VDB</h5><p>适配不同数据源和生成虚拟数据库（VDB）需要维护好几个配置文件，可参考<a href="http://blog.csdn.net/scorpio3k/article/details/24466065" target="_blank" rel="external">Teiid 基于数据联邦的集成方案</a>中的最后部分“建立虚拟数据库”，比较复杂，一般创建和部署可使用Teiid提供的辅助工具Teiid Designer来完成。</p>
<h5 id="Teiid-Designer-配置"><a href="#Teiid-Designer-配置" class="headerlink" title="Teiid Designer 配置"></a>Teiid Designer 配置</h5><ol>
<li>打开 Eclipse，选择 Help &gt; Install New Software</li>
<li>地址栏输入如下地址：<a href="http://download.jboss.org/jbosstools/updates/release/neon/integration-stack/teiiddesigner/11.0.0.Final/" target="_blank" rel="external">http://download.jboss.org/jbosstools/updates/release/neon/integration-stack/teiiddesigner/11.0.0.Final/</a></li>
<li>选择插件工具 Data Virtualization，一直点击下一步，安装完毕后，重启Eclipse</li>
</ol>
<h5 id="Teiid-Designer-实践"><a href="#Teiid-Designer-实践" class="headerlink" title="Teiid Designer 实践"></a>Teiid Designer 实践</h5><p>测试案例为一个ORACLE测试库和一个CSV测试文件的数据联邦。以下为具体步骤：</p>
<ol>
<li>启动与设置 Teiid Server<ol>
<li>打开配置好 Teiid Designer 插件的 Eclipse，切换至 Teiid Designer 视图</li>
<li>点击Default Server下的No default server define，参考<strong>在 Eclipse中配置 Teiid server</strong>，设置 Teiid Server</li>
<li>完成后Default Server变成新建服务器，启动服务器，在Server配置页Teiid Instance中配置JDBC连接</li>
</ol>
</li>
<li>创建 Teiid Model 工程<ol>
<li>在 Teiid Designer 的 Model Explorer视图中，右击选择 New &gt; Teiid Model Project</li>
<li>输入工程名后，点击下一步，Create Folders 界面勾选要创建的 Folders 后，完成创建</li>
</ol>
</li>
<li>导入 ORACLE 数据源<ol>
<li>在 Guides 中，选择 Model JDBC Source，下方窗口显示具体操作选项</li>
<li>双击 Define Teiid Model Project ，选择之前创建的 Teiid Model 工程</li>
<li>双击 Create JDBC connection，在弹出的窗口中，选择 Oracle 数据库，然后点下一步</li>
<li>选择 Oracle 驱动，配置好 Oracle 数据源的的 url、用户名、密码后，点击完成</li>
<li>双击 Create source model for JDBC data source，一直下一步，直到选择数据库和表</li>
<li>选择所需数据库和表，点下一步，自定义 Model Name（Oracle.xmi），其他默认，点击完成</li>
<li>双击 Preview Data，在弹框中选择需要 preview 的表或者 precedure ，结果显示在 SQL Result 框中<blockquote>
<p>运行Preview Data时，会跳出提示(Required data sources are not deployed …)，点击Yes，数据源将在服务器创建和部署。</p>
</blockquote>
</li>
</ol>
</li>
<li>导入 CSV 数据源<ol>
<li>在 Guides 中，选择 Model Flat File Source，下方窗口显示具体操作选项</li>
<li>双击 Define Teiid Model Project ，选择之前创建的 Teiid Model 工程</li>
<li>双击 Create Flat File connection，在弹出的窗口中，点击下一步，设置CSV所在目录，然后点击完成</li>
<li>双击 Create source model for local flat file source，点击下一步，直到选择CSV文件窗口</li>
<li>选择所需CSV文件，按照默认配置一直下一步，在view model definition 界面，设置含合法字符的table view ，点击Finish</li>
<li>双击 Preview Data，在弹框中选择需要 preview 的<strong>views</strong>目录下的表，结果将显示在 SQL Result 框中<blockquote>
<p>运行Preview Data时，会跳出提示(Required data sources are not deployed …)，点击Yes，数据源将在服务器创建和部署。</p>
</blockquote>
</li>
</ol>
</li>
<li>生成虚拟数据库<ol>
<li>在 Guides 中，选择之前设置过的 Model JDBC Source 或者 Model Flat File Source</li>
<li>双击 Define VDB &gt; New… ，输入VDB名，Add添加之前导入的数据源（包括sources和views），点击Finish</li>
<li>Define VDB 自动显示新建VDB，点击确定，Define VDB下的Edit VDB和Execute VDB自动关联对应VDB</li>
</ol>
</li>
<li>部署虚拟数据库<ol>
<li>在 Guides 中，选择<strong>生成虚拟数据库</strong>步骤所在的选项</li>
<li>双击 Execute VDB ，之前已自动关联VDB，点击OK运行后，自动跳转到Database Development视图中</li>
<li>在跳转的界面中，可选择对应类型和Database，查询之前设置的Oracle和CSV数据源中的数据<blockquote>
<p>运行Execute VDB，Teiid Designer会部署自动虚拟数据库(VDB)到服务器中。</p>
</blockquote>
</li>
</ol>
</li>
</ol>
<p>注意：以上操作会修改Teiid Server中的配置，比如standalone-teiid.xml，故在命令行运行添加VDB后的服务器时，需使用以下命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">C:\Users\Administrator&gt;cd C:\teiid-9.3.5\bin</div><div class="line">C:\teiid-9.3.5\bin&gt;standalone.bat -c standalone-teiid.xml</div></pre></td></tr></table></figure>
<h4 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h4><ol>
<li><p>关于性能和时延</p>
<p> Teiid是数据联邦的开源实现，优点是可将各类不同数据集合到一个虚拟数据源中，能方便和实时的获取数据；缺点是随着数据量增大，Teiid将面临性能方面的问题。</p>
<p> 如<a href="http://blog.csdn.net/scorpio3k/article/details/24466065" target="_blank" rel="external">Teiid 基于数据联邦的集成方案</a>描述：</p>
<blockquote>
<p>与其它数据集成技术相比，数据联邦技术的明显优势在于获取数据的方便性和实时性。现在很多企业都在实现 SOA，SOA 的灵活性和敏捷性要求组织提供数据时应该具有更少的时延。以前的利用批量任务或者 ETL 的方式创建数据集市和数据仓库的方式的实时性都不太好，在很多应用场景中被数据联邦技术所取代。</p>
<p>但是数据联邦技术访问数据是通过一个“联邦”视图（federation view）来实现的，视图是实时的。随着企业数据量的增大，性能问题是所有数据集成（Data Integration tools）都面临的问题，但是由于设计上的根本缺陷，数据联邦在这方面虽有很大进展，但是仍无法和另外一些数据集成技术相比。这种缺点制约了它在数据集成领域的适用性，虽然很多领域都使用了数据联邦技术，但是在关键的核心业务系统它的应用非常少。</p>
<p>目前已实施数据联邦项目的特点如下：使用简单的有限的数据源，数据结果集不大，只读性的数据访问，数据质量要求简单。比较典型数据联邦产品有：BEA 的 AquaLogic Data Services Platform、IBM 公司的 Federation Server、Software AG 公司的 Enterprise Information Integration、Sybase 的 DataFederation 以及 Red Hat 公司的 JBoss MetaMatrix，其开源实现即 Teiid。</p>
</blockquote>
</li>
<li><p>关于Teiid组件版本兼容</p>
<p> Teiid Server版本是Teiid 9.3.5，Teiid Designer插件版本是11.0.1，使用Eclipse创建VDB时，经常有报错信息，可能是两者的兼容问题引起。</p>
</li>
<li><p>部分JDBC Source无法Create source model</p>
<p> 比如，创建SQL Server数据库source model时，JDBC Source连接和访问正常，但之后创建的source model无法显示列和数据，原因未知。</p>
</li>
</ol>

			
		</div><!-- .entry-content -->
		
			<div class="entry-comments">
				 
  
   
      <!-- ��˵���ۿ� start -->
	<div class="ds-thread" data-thread-key="2017/12/08/TeiidUseNote/" data-title="Teiid搭建和使用小记" data-url="http://vfface.oschina.io/2017/12/08/TeiidUseNote/"></div>
<!-- ��˵���ۿ� end -->
<!-- ��˵����JS���� start (һ����ҳֻ������һ��) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"troyyang"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.unstable.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
<!-- ��˵����JS���� end -->
 
			</div>
		
		<footer class="entry-footer">
			<span class="posted-on font-asesome-icon">
	<a href="" rel="bookmark">
	<time class="updated" datetime="2017-12-07T16:00:00.000Z">2017-12-08</time>
	</a>
</span>

	<span class="cat-links font-asesome-icon">
		
				<a href="/categories/平台/" rel="category tag">平台</a>
		
	</span>


	<span class="tags-links font-asesome-icon">
	
		<a href="/tags/Teiid/" rel="category tag">Teiid</a>
    
</span>
		

    <span class="eye font-asesome-icon" >
         <span id="/2017/12/08/TeiidUseNote/" class="leancloud_visitors" data-flag-title="Teiid搭建和使用小记">
        
        </span>
    </span>

		</footer><!-- .entry-footer -->
</article>
<div class="misc">
    <a href="#main"><span class="top font-asesome-icon">Top</span></a>
</div>
			</main>
		</div>
		<footer id="colophon" class="site-footer">
			<div class="site-info">
				<span>powered by <a href="https://hexo.io/">Hexo</a>&nbsp;&nbsp; theme by <a href="https://github.com/Troy-Yang/hexo-theme-twentyfifteen-wordpress">Troy</a> &nbsp; inspired by <a href="https://wordpress.org/themes/">wordpress</a></span>
			</div><!-- .site-info -->
		</footer>
	</div>
    <!-- After footer scripts -->
    <script src="/js/jquery-3.1.1.min.js"></script>
<script src="/js/main.js"></script>

    <!--referring from https://notes.wanghao.work/2015-10-21-%E4%B8%BANexT%E4%B8%BB%E9%A2%98%E6%B7%BB%E5%8A%A0%E6%96%87%E7%AB%A0%E9%98%85%E8%AF%BB%E9%87%8F%E7%BB%9F%E8%AE%A1%E5%8A%9F%E8%83%BD.html -->
    <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
    <script>
        AV.initialize("wzqncxgqp9MCPiPERe3gnX2Q-gzGzoHsz", "CCtBiqyPtJWupuozt1393AXm");
    </script>
    <script>
        function showTime(Counter) {
            var query = new AV.Query(Counter);
            $(".leancloud_visitors").each(function () {
                var url = $(this).attr("id").trim();
                query.equalTo("url", url);
                query.find({
                    success: function (results) {
                        if (results.length == 0) {
                            var content = $(document.getElementById(url)).text() + ': 0';
                            $(document.getElementById(url)).text(content);
                            return;
                        }
                        for (var i = 0; i < results.length; i++) {
                            var object = results[i];
                            var content = $(document.getElementById(url)).text() + ': ' + object.get('time');
                            $(document.getElementById(url)).text(content);
                        }
                    },
                    error: function (object, error) {
                        console.log("Error: " + error.code + " " + error.message);
                    }
                });
            });
        }
        function addCount(Counter) {
            var Counter = AV.Object.extend("Counter");
            url = $(".leancloud_visitors").attr('id').trim();
            title = $(".leancloud_visitors").attr('data-flag-title').trim();
            var query = new AV.Query(Counter);
            query.equalTo("url", url);
            query.find({
                success: function (results) {
                    if (results.length > 0) {
                        var counter = results[0];
                        counter.fetchWhenSave(true);
                        counter.increment("time");
                        counter.save(null, {
                            success: function (counter) {
                                var content = $(document.getElementById(url)).text() + ': ' + counter.get('time');
                                // remove ': '
                                $(document.getElementById(url)).text(counter.get('time'));
                            },
                            error: function (counter, error) {
                                console.log('Failed to save Visitor num, with error message: ' + error.message);
                            }
                        });
                    } else {
                        var newcounter = new Counter();
                        newcounter.set("title", title);
                        newcounter.set("url", url);
                        newcounter.set("time", 1);
                        newcounter.save(null, {
                            success: function (newcounter) {
                                console.log("newcounter.get('time')=" + newcounter.get('time'));
                                var content = $(document.getElementById(url)).text() + ': ' + newcounter.get('time');
                                // remove ': '
                                $(document.getElementById(url)).text(newcounter.get('time'));
                            },
                            error: function (newcounter, error) {
                                console.log('Failed to create');
                            }
                        });
                    }
                },
                error: function (error) {
                    console.log('Error:' + error.code + " " + error.message);
                }
            });
        }
        $(function () {
            var Counter = AV.Object.extend("Counter");
            if ($('.leancloud_visitors').length == 1) {
                addCount(Counter);
            } else if ($('.post-title-link').length > 1) {
                showTime(Counter);
            }
        });
    </script>
    
</body>
</html>